package de.unimannheim.ki.algorithmn;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import de.unimannheim.ki.databaseentities.MusicObject;
import de.unimannheim.ki.databaseentities.Musicuser;

public class LikeDisJoint implements IComparator {

	@Override
	public List<Neighbour> computeDistance(List<Musicuser> users,
			Musicuser compareuser) {

		ArrayList<Neighbour> neighbours = new ArrayList<Neighbour>();

		List<MusicObject> myLikedObjects = compareuser.getObjects();

		for (int i = 0; i < users.size(); i++) {

			double likeQuota = 0.0;

			Musicuser mu = users.get(i);

			if (mu.getFbid().equals(compareuser.getFbid()))
				continue;

			List<MusicObject> muLikes = mu.getObjects();
			// System.out.println("Likes of our user: "+ myLikedObjects.size());
			// System.out.println("Likes of current tested user: "+
			// muLikes.size());

			// keep only the intersection of both lists
			muLikes.retainAll(myLikedObjects);
			// System.out.println("Intersection likes: "+ muLikes.size());

			if (muLikes.size() > 0 && myLikedObjects.size() > 0) {
				likeQuota = (double) muLikes.size() / myLikedObjects.size();
			}

			// System.out.println("Quota: "+likeQuota);
			neighbours.add(new Neighbour(likeQuota, mu));

		}// end for

		Collections.sort(neighbours);

		return neighbours;
	}

}
